// 题目链接：https://leetcode.cn/problems/find-first-and-last-position-of-element-in-sorted-array/

class Solution {
    public:
        int binary_search1(vector<int>& nums, int target) {
            int l = -1, r = nums.size();
            int mid;
            while(l + 1 < r) {
                mid = (l + r) / 2;
                if(nums[mid] < target)
                    l = mid;
                else
                    r = mid;
            }
            return r;
        }
        int binary_search2(vector<int>& nums, int target) {
            int l = -1, r = nums.size();
            int mid;
            while(l + 1 < r) {
                mid = (l + r) / 2;
                if(nums[mid] <= target)
                    l = mid;
                else
                    r = mid;
            }
            return l;
        }
        vector<int> searchRange(vector<int>& nums, int target) {
            int res1 = binary_search1(nums, target);
            int res2 = binary_search2(nums, target);
    
            if(res1 > res2) {
                return {-1, -1};
            }
            else {
                return {res1, res2};
            }
        }
    };